package com.demo.core.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.demo.base.model.UserInfo;
import com.demo.base.util.CommonUtil;

@Repository
public class UserInfoDao extends BaseDao{

	/**
	 * 用户登录时查询用户是否存在
	 * @param loginName
	 * @param password
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public UserInfo userAuth(String loginName,String password,String password1){
		
		StringBuffer sql = new StringBuffer();
		
		sql.append("from UserInfo where loginName=:loginName and (firstPassword = :firstPassword or password = :password)");
		Session session = this.getSession();
		Query query = session.createQuery(sql.toString());
		query.setString("loginName",loginName);
		query.setString("firstPassword", password1);
		query.setString("password", password);
		List<UserInfo> list = query.list();
		
		if(!CommonUtil.isNull(list)){
			
			return list.get(0);		
			}else{
				
				return null;
		}
	}
}
